package com.zretc.controller;

import com.util.Result;
import com.zretc.pojo.CustomerInfo;
import com.zretc.pojo.FinancialSituation;
import com.zretc.service.CustomerService;
import com.zretc.service.FinancialSituationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Filename:    CodeMsg.java
 * Description: 财产接口 控制器
 * Copyright:   Copyright (c) 2022-2025 All Rights Reserved.
 * Company:     chinasofti.com Inc.
 *
 * @author: xujingyi
 * @version: 1.0
 * Create at:   2022-09-01
 * <p>
 * Modification History:
 * Date         Author      Version     Description       tag
 * ------------------------------------------------------------------
 * xujingyi
 */
@RestController
@Api("财务模块")
@ApiOperation("FinancialSituationController")
public class FinancialSituationController {
    @Autowired
    private FinancialSituationService FinancialSituationService;

    /**
     * 获取所有客户信息
     * 啊啊啊
     *
     * @param idCard 身份id
     * @return
     */
    @GetMapping("/findFinancialSituationByIdCard")
    public Result<FinancialSituation> findFinancialSituationByIdCard(String idCard) {
        // 根据身份证询客户的财产状况
        FinancialSituation FinancialSituation = FinancialSituationService.findFinancialSituationByIdCard(idCard);
        /*身份证校验*/
        /*===============================*/
        if (isCard(idCard)) {
            System.out.println("身份证号码正确");
            return Result.success(FinancialSituation);
        } else {
            return null;
        }
        /*=================================*/
        // 返回值
//        return Result.success(FinancialSituation);
    }
    /*=================================*/

    /**
     * 验证身份证真假
     *
     * @param carNumber 身份证号
     * @return boolean
     */
    public static boolean isCard(String carNumber) {
        //判断输入身份证号长度是否合法
        if (carNumber.length() != 18) {
            throw new RuntimeException("身份证长度不合法");//不合法 抛出一个异常
        }
        //校验身份证真假
        int sum = 0;
        int[] weight = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};//将加权因子定义为数组
        //遍历weight数组 求身份证前17项系数和
        for (int i = 0; i < weight.length; i++) {
            int n = carNumber.charAt(i) - 48;//获取 身份证对应数
            int w = weight[i];
            sum += w * n;
        }
        //对11求余
        int index = sum % 11;
        //校验码

        String m = "10X98765432";
        //获取身份证最后一位进行比对
        return m.charAt(index) == carNumber.charAt(17);
    }
    /*=================================*/


}
